<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Register {
	protected $CI;
    public function register()
    {
		
		$this->CI =& get_instance();
    }
	
	/**
	 * Required
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	public function re_required($str)
	{
		return ( ! empty($str));
	}
	
	public function re_max_length($str,$num)
	{
		if (preg_match("/[^0-9]/", $num))
		{
			return FALSE;
		}

		if (function_exists('mb_strlen'))
		{
			return (mb_strlen($str) > $num) ? FALSE : TRUE;
		}

		return (strlen($str) > $num) ? FALSE : TRUE;
	}
	
	public function re_min_length($str,$num)
	{
		if (preg_match("/[^0-9]/", $num))
		{
			return FALSE;
		}

		if (function_exists('mb_strlen'))
		{
			return (mb_strlen($str) < $num) ? FALSE : TRUE;
		}

		return (strlen($str) < $num) ? FALSE : TRUE;
	}
	
	public function re_valid_email($str)
	{
		return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
	}
	
	/**
	 * Alpha
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	public function re_alpha($str)
	{
		return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
	}
	
	/*
	 *
	 * Alpha-numeric
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	 
	public function re_alpha_numeric($str)
	{
		return preg_match('/^[a-zA-Z0-9]+$/', $str);
	}
	
	/**
	 * Numeric
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	public function re_numeric($str)
	{
		return (bool) preg_match( '/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
	}
	
	/**
	 * Is Numeric
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	public function is_numeric($str)
	{
		return ( ! is_numeric($str)) ? FALSE : TRUE;
	}
	
	/**
	 * Integer
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	public function re_integer($str)
	{
		return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
	}
	
	
	public function re_is_unique($str, $field,$table)
	{
		list($table, $field)=explode('.', $field);
		$query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
		return $query->num_rows() === 0;
    }
	
	function re_length($str, $min=NULL, $max=NULL){
		$str_length = strlen($str);
		if($min != NULL && $max != NULL){
			if($str_length >= $min && $str_length <= $max){
				return true;
			}else{
				return false;
			}
		}elseif ($min != NULL) {
			if($str_length >= $min){
				return true;
			}else{
				return false;
			}
		}else{
			if($str_length <= $max){
				return true;
			}else{
				return false;
			}
		}
	}
}

/* End of file Someclass.php */